package com.viknix.threadpool.manager.config.dump;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author: Dongqi
 * @Date: 2021/11/22 10:50
 * @Version 1.0
 * @Description: ConfigInfo.
 */
@Data
@NoArgsConstructor
public class ConfigInfo implements Serializable, Comparable<ConfigInfo> {

    static final long serialVersionUID = -1L;

    @JsonSerialize(using = ToStringSerializer.class)
    private long id;

    private String namespace;

    private String threadPoolId;

    private String projectId;

    private String content;

    private String md5;

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public int compareTo(ConfigInfo o) {
        if (o == null) {
            return 1;
        }
        if (this.threadPoolId == null) {
            if (o.getThreadPoolId() == null) {
                return 0;
            } else {
                return -1;
            }
        } else {
            if (o.getThreadPoolId() == null) {
                return 1;
            } else {
                int cmpDataId = this.threadPoolId.compareTo(o.getThreadPoolId());
                if (cmpDataId != 0) {
                    return cmpDataId;
                }
            }
        }

        if (this.projectId == null) {
            if (o.getProjectId() == null) {
                return 0;
            } else {
                return -1;
            }
        } else {
            if (o.getProjectId() == null) {
                return 1;
            } else {
                int cmpGroup = this.projectId.compareTo(o.getProjectId());
                if (cmpGroup != 0) {
                    return cmpGroup;
                }
            }
        }

        if (this.content == null) {
            if (o.getContent() == null) {
                return 0;
            } else {
                return -1;
            }
        } else {
            if (o.getContent() == null) {
                return 1;
            } else {
                int cmpContent = this.content.compareTo(o.getContent());
                if (cmpContent != 0) {
                    return cmpContent;
                }
            }
        }
        return 0;
    }
}
